﻿using System;
using System.Security.Claims;

namespace LF.Application.Extend
{
	public static class ClaimEx
	{
        public static Guid? GetUserId(this ClaimsPrincipal claimsPrincipal)
        {
            try
            {
                var claim = claimsPrincipal?.Claims.FirstOrDefault(c => c.Type == "Id");
                if (claim == null || string.IsNullOrEmpty(claim.Value))
                {
                    return null;
                }

                return Guid.Parse(claim.Value);
            }
            catch
            {
                return null;
            }
        }
    }
}